<template>
    <div>
        <h2>房号添加页面</h2>

        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房号名称</td>
                    <td>
                        <input type="text" v-model="quertinfo.NumName">
                    </td>
                </tr>

                <tr>
                    <td>房型名称</td>
                    <td>
                        <input type="text" v-model="quertinfo.HouseName">
                    </td>
                </tr>

                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" name="state" :value="0" v-model="quertinfo.State">营业
                        <input type="radio" name="state" :value="1" v-model="quertinfo.State">停业
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-danger" @click="ok">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import axios from 'axios';
import {useRoute,useRouter} from 'vue-router'
const router=useRouter();
const route=useRoute();

import moment from 'moment'

let quertinfo=reactive({
  "NumName": "",
  "HouseName": "",
  "State": '',
})

const ok=()=>{
    //有效性验证
    if(quertinfo.NumName==""){
        alert('房号不能为空');
        return;
    }

    if(quertinfo.HouseName==""){
        alert('房型不能为空');
        return;
    }

    if(quertinfo.State===""){
        alert('状态必选');
        return;
    }

    //返回网络请求
    axios({
        method:'post',
        url:'/api/HouseNum/AddNum',
        data:quertinfo
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert('房号不能重复');
            return;
        }
        if(res.data>0){
            alert('成功');
            router.push('/');
        }
        else{
            alert('失败');
        }
    })
    .catch(err=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>